import 'package:cool_ui/cool_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
class Student {
  final String objectId;
  final String title;
  final String state;
  final Color color;
  double interval;
  bool select;
  Student(this.objectId, this.title, this.state,this.color,this.select,this.interval);
}
//appbar會員的學生狀態欄
class AppBarActions extends StatefulWidget {
  @override
  _AppBarActionsState createState() => _AppBarActionsState();
}

class _AppBarActionsState extends State<AppBarActions> {
  List<Student> studentList = [Student('','陳大文','等待接送中',Color(0Xff72c0a4),true,0),Student('','陳二文','補習中',Color(0Xffcf6d6d),false,0),Student('','陳三文','補習中',Color(0Xffe9b525),false,0)];
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, designSize: Size(375, 667), allowFontScaling: false);
    return CupertinoPopoverButton(
        child: Container(
          child: Row(
            children: <Widget>[
              Container(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Container(
                      child: Text(
                        studentList.first.title,
                        style: TextStyle(
                          fontWeight:
                          FontWeight.bold,
                          color: Color(0XFFFFFFFF),
                          fontSize: ScreenUtil().setSp(12),
                          fontFamily:"SemiBold",
                        ),
                      ),
                    ),
                    Container(
                      child: Text(
                        studentList.first.state,
                        style: TextStyle(
                          color: Color(0XffD7FFAC),
                          fontSize: ScreenUtil().setSp(12),
                          fontFamily:"SemiBold",
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                  width: 30+(studentList.length*10).toDouble(),
                  child: Stack(
                    children: <Widget>[
                      Positioned(
                        left:20,
                        child: Container(
                          width: 30,
                          height: 30,
                          decoration: BoxDecoration(
                              color: Color(0Xff72c0a4),
                              borderRadius:
                              BorderRadius.circular(
                                  50)),
                        ),
                      ),
                      Positioned(
                        left: 10,
                        child: Container(
                          width: 30,
                          height: 30,
                          decoration: BoxDecoration(
                              color: Color(0Xffcf6d6d),
                              borderRadius:
                              BorderRadius.circular(
                                  50)),
                        ),
                      ),
                      Positioned(
                        child: Container(
                          width: 30,
                          height: 30,
                          decoration: BoxDecoration(
                              color: Color(0Xffe9b525),
                              borderRadius:
                              BorderRadius.circular(
                                  50)),
                        ),
                      ),
                    ],

                  )
              ),
            ],
          ),
        ),
        //彈出選擇學生
        popoverBuild: (BuildContext context) {
          return CupertinoPopoverMenuList(
            children: studentList.map((student){
              return GestureDetector(
                child: CupertinoPopoverMenuItem(
                  leading: Center(child: Container(
                    width: 25,
                    height: 25,
                    decoration: BoxDecoration(
                        color: student.color,
                        borderRadius:
                        BorderRadius.circular(50)),
                  ),),
                  child: GestureDetector(
                    onTap: (){
                      setState(() {
                        if(identical(studentList.first,student)){
                          return;
                        }else{
                          var stu ;
                          stu  = studentList.first;
                          stu.select = false;
                          studentList.remove(student);
                          student.select = true;
                          studentList.first = student;
                          studentList.add(stu);
                        }
                      });
                      Navigator.of(context).pop();
                    },
                    child: Column(
                      children: <Widget>[
                        Container(
                          child: Text(
                            student.title,
                            style: TextStyle(
                                fontWeight:
                                FontWeight.bold,
                                color: student.select == true?Color(0Xff4d80c5):Colors.black,
                                fontSize: 15
                            ),
                          ),
                        ),
                        Container(
                          child: Text(
                            student.state,
                            style: TextStyle(
                                color: Color(0Xffe3e4b3),
                                fontSize: 14
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              );
            }).toList(),
          );
        });
  }
}

